export class MailUtil {
  /**
   *  hmtest1028@sina.com              hmtest1028
   *  张三 <zhangsan@coremail.cn>       张三
   * @param address
   * @returns
   */
  static parseNameFromAddress(address: string): string {
    if (!address) {
      return ""
    }
    let index = address.indexOf("<");
    if (index > 0) {
      return address.substring(0, index).trim();
    } else {
      return address.substring(0, address.indexOf("@")).trim()
    }
  }

  /**
   *  hmtest1028@sina.com              hmtest1028@sina.com
   *  张三 <zhangsan@coremail.cn>       zhangsan@coremail.cn
   * @param address
   * @returns
   */
  static parseEmailFromAddress(address: string): string {
    if (!address) {
      return ""
    }
    let start = address.indexOf("<");
    let last = address.indexOf(">");
    if (start >= 0 && start < last) {
      // 起点 start 则包含< ，所以+1， 终点 last 不包含 >
      return address.substring(start + 1, last).trim();
    }
    // 存在 " hmtest1028@sina.com" 的情况，所以加 trim()
    return address.trim();
  }
}